package beautiful.butterfly.distributed_task_processing_engine.task_manage;

import lombok.extern.slf4j.Slf4j;

import java.util.TimerTask;

@Slf4j
public class JvmInstanceIdStatusAndTaskManageTimerTask extends TimerTask
{

    JvmInstanceStatusAndTaskManage jvmInstanceStatusAndTaskManage;
    int count = 0;

    public JvmInstanceIdStatusAndTaskManageTimerTask(JvmInstanceStatusAndTaskManage jvmInstanceStatusAndTaskManage)
    {
        this.jvmInstanceStatusAndTaskManage = jvmInstanceStatusAndTaskManage;
    }

    public void run()
    {
        try
        {
            Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
            if (!this.jvmInstanceStatusAndTaskManage.zooKeeperManager.zooKeeperIsConnected())
            {
                if (count > 5)
                {
                    this.jvmInstanceStatusAndTaskManage.reStart();//对象并行处理模型
                } else
                {
                    count = count + 1;
                }
            } else
            {
                count = 0;

                this.jvmInstanceStatusAndTaskManage.jvmInstanceStatusAndTaskManage();
            }

        } catch (Throwable ex)
        {
            log.error(ex.getMessage(), ex);
        } finally
        {
            jvmInstanceStatusAndTaskManage.timerTaskHeartBeatTimeMillis = System.currentTimeMillis();
        }
    }
}
